/*
 * Copyright (C) 2020 Jimmy Hogoboom
 *
 * This file is part of Limitlist.
 *
 * Limitlist is free software: you can redistribute it and/or modify
 * it under the terms of the Affero GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Limitlist is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Affero GNU General Public License for more details.
 *
 * You should have received a copy of the Affero GNU General Public License
 * along with Limitlist.  If not, see <https://www.gnu.org/licenses/>.
 */

// SPDX-License-Identifier: AGPL-3.0-or-later

import ls from 'local-storage';
import { IProductListItem } from 'core/types/IProductListItem';

export interface IStorage {
    Lists: ILists,
}

export interface ILists {
    find: (id: string) => Promise<IProductListItem[]>,
    set: (id: string, list: IProductListItem[]) => void,
}

const Lists = {
    find: async (id: string) => {
        const list = ls<IProductListItem[]>(id) as unknown as IProductListItem[];
        if (!list) return [];

        return list;
    },
    set: async (id: string, list: IProductListItem[]) => {
        ls(id, list);
    },
}

export default {
    Lists,
} as IStorage;
